function displaySubMenu(li) { 
	var subMenu = li.getElementsByTagName("div")[0]; 
	subMenu.style.display = "block"; 
} 
function hideSubMenu(li) { 
	var subMenu = li.getElementsByTagName("div")[0]; 
	subMenu.style.display = "none"; 
}

function onsavelink()
{
	var name = $("#name").val();
	var id = $("#id").val();
	var tlinks = $("#tlinks").val();
	var power = $("#power").val();
	var remark = $("#remark").val();
	var sort_id = $("#sort_id").val();
	var sortts= $("#sort").val();
	var isshow =$("input:radio[name='isshow']:checked").val();
	
	if(!name)
	{
		alert("带*号内容必须填写");
		return;
	}

	$.post("/management/ajaxbutton", {"op": "savevalue","valuetxt":name,"value_fied":tlinks,"id":id,"sort_id":sort_id,"remark":remark,"power":power,"sort":sortts,"isshow":isshow},
	  function(data){
			if(data ==201)
			{
				alert("已被占用!");
				return;
			}else if(data==202)
			{
				alert("目前只支持三级目录!");
				return;
			}else{
				//显示数据
				if(id){
					document.location.href = "/management/development";
					return;
				}
				showgroup();
				return;
			}
	   },"json");
}


function delatt(o)
{
	if(confirm("确定移除?"))
	{
		$(o.parentNode.parentNode).remove();
	}
}
function delproduct(id)
{
	if(confirm("确定移除?"))
	{
		$.post("/oversea/ajaxbutton", {"op": "delproduct","id":id},
		  function(data){
				
			document.location.href = "/oversea/product";
			return;
		   },"json");
	}
}
function delwarehouse(id)
{
	if(confirm("确定移除?"))
	{
		$.post("/oversea/ajaxbutton", {"op": "delwarehouse","id":id},
		  function(data){
				
			document.location.href = "/oversea/warehouse";
			return;
		   },"json");
	}
}
function delstatuslist(id,planid)
{
	if(confirm("确定移除?"))
	{
		$.post("/oversea/ajaxbutton", {"op": "delstatuslist","id":id},
		  function(data){
			document.location.href = "/oversea/showplan/"+planid;
			return;
		   },"json");
	}
}

function getsku(id)
{
	var sku = $("#sku").val();
	$.post("/oversea/ajaxbutton", {"op": "getsku","sku":sku},
		  function(data){
					if(data==200)
					{
					
					}else{
							$("#skuerr").html('商品编号(SKU)['+sku+']已经存在！');
							$("#sku").val('');
					return false;
					}
			return;
		   },"json");
}

function saveproduct()
{
	if($("#sku").val()=="")
	{
		$("#skuerr").html('商品编号(SKU)不能为空！');
		return false;
	}
	if($("#name").val()=="")
	{
		$("#nameerr").html('不能为空！');
		return false;
	}
	if($("#costprice").val()=="")
	{
		$("#costpriceerr").html('商品成本价不能为空！');
		return false;
	}
	$("#theFrom").submit();
}
function purchasingNext()
{
	var seawarehouse = $("#seawarehouse").val();
	var shopname = $("#shopname").val();
	var sku = $("#sku").val();
	if(seawarehouse=="")
	{
		alert("请选择发往仓库!");
		
		return;
	}

	if(seawarehouse.indexOf('Amazon') >=0)
	{
		if(shopname=="")
		{
			alert("目的地为Amazon时，必须选择店铺！");
				return;
		}
	}
	
	if(sku=="")
	{
		alert("请填写sku!");
		$("#sku").focus();
		return;
	}
	$.post("/oversea/ajaxbutton", {"op": "savepurchasingNext","seawarehouse":seawarehouse,"shopname":shopname,"sku":sku},
	  function(datats){
			if(datats ==202)
			{
				alert("没有找到SKU!");
				return;
			}else{
				if(datats.nosku)
				{
					alert("存在未列入海外仓列表的SKU 如下：\r\n"+datats.nosku+"");
				}
				var data = datats.listdata;
				

				var tmp='<br><table cellpadding="0" cellspacing="0" border="0" class="stdtable">';
				tmp+=' <colgroup><col class="con1" /><col class="con0" /><col class="con1" /><col class="con0" /><col class="con1" /><col class="con0" /><col class="con1" /></colgroup>';
				tmp+='<thead><th class="head0">移除</th><th class="head0">商品编号</th><th class="head1">商品名称</th><th class="head0">成本价</th><th class="head0">数量</th><th class="head0">备注</th></tr> </thead>';
				for(var i=0;i<data.length;i++)
				{
					tmp+=" <tr>";
					tmp +="<td><img src=/fuman/images/del.png class=p_del  style=\"cursor:pointer\" title=\"不需要这个SKU\" onclick=\"delatt(this)\"></td><td>"+data[i].sku+"</td><td>"+data[i].name+"</td><td>"+data[i].costprice+"</td><td><input type=\"text\" name=\"skusum[]\"  id=\"skusum\" class=\"longinput\" style='width:100px;' /></td><td><input type=\"text\" name=\"remark[]\" id=\"remark\" class=\"longinput\"  /><input type=\"hidden\" name=\"skuid[]\" value="+data[i].id+"  /><input type=\"hidden\" name=\"goodsno[]\" value="+data[i].sku+"  /></td>" ;
					tmp+=" </tr>";
				}
				tmp+="</table>";
				//$("#sku").attr("disabled","disabled");
				$("#prespan").html(''); 
				$("#prespan").html('<button type="button" class="submit radius2" id="btn" onClick="purchasingNext()">追加SKU</button>&nbsp;&nbsp;&nbsp;<button type="button" class="submit radius2" id="btn" onClick="savepurchasing()">确定保存</button>'); 
    		      $("#showskulist").html(tmp);    
			}
	   },"json");
	
	
}
function savepurchasing()
{
	var st=0;
	$("input[id='skusum']").each(function () {
			if ($(this).val() == "") {
				alert("数量必须全部填写，不能留空！");
				$(this).focus;
				st = 1;
				return;
			}
		})
	if(st==0){
	$("#theFrom").submit();
		}
}
function delpurlist(id)
{
	if(confirm("确定移除?"))
	{
		$.post("/oversea/ajaxbutton", {"op": "delpurlist","id":id},
		 function(data){
				
			document.location.href = "/oversea/purchasinglist";
				return;
			

	   },"json");
	}
}
function getpurchprolist()
{
	var endhouse = $("#endhouse").val();
	var shopname = $("#shopname").val();
	if(endhouse.indexOf('Amazon') >=0)
	{
		if(shopname=="")
		{
			alert("目的地为Amazon时，必须选择店铺！");
				return;
		}
	}



	$.post("/oversea/ajaxbutton", {"op": "getpurchprolist","endhouse":endhouse,"shopname":shopname},
	  function(data){
			if(data ==202)
			{
				alert("没有找到SKU!");
				return;
			}else{

				
				var newti = "";
				var is =0;
				var tmp='<br><table cellpadding="0" cellspacing="0" border="0" class="stdtable">';
				tmp+=' <colgroup><col class="con1" /><col class="con0" /><col class="con1" /><col class="con0" /><col class="con1" /><col class="con0" /><col class="con1" /></colgroup>';
				tmp+='<thead><th class="head0"><input name="allchk" id="allchk" type="checkbox" onClick="allSelect(\'competenceID[]\')"></th><th class="head0">明细</th><th class="head0">总计需发数量</th><th class="head0">商品编号</th><th class="head1">商品名称</th><th class="head0">成本价</th></tr> </thead>';
				for(var i=0;i<data.length;i++)
				{
					is = 1;
						var goodslist = data[i].goodslist;
						newti+=' <table cellpadding="0" cellspacing="0" border="0" class="stdtable">';
						for(var k=0;k<goodslist.length;k++)
						{
							newti+=" <tr>";
							newti+= "<td>"+goodslist[k].createUser+"</td><td>预订："+goodslist[k].skunum+"</td><td>备注："+goodslist[k].remark+"</td><td><input type=\"text\" name=\"realsend["+data[i].oversearproduct_id+"][]\" value="+goodslist[k].skunum+" id=\"realsend\" class=\"longinput\" style='width:30px;' /><input type=\"hidden\" name=\"overseapurchasing["+data[i].oversearproduct_id+"][]\" value="+goodslist[k].id+"  /></td>";
							newti+=" </tr>";
						}
						newti+=" </table>";
					tmp+=" <tr>";
					tmp +="<td><input type=\"checkbox\" name=\"competenceID[]\"  value="+data[i].oversearproduct_id+" /> </td><td>"+newti+"</td><td>"+data[i].totalnum+"</td><td>"+data[i].goodsno+"</td><td>"+data[i].name+"</td><td>"+data[i].costprice+"</td>" ;
					tmp+=" </tr>";
					newti = "";
				}
				tmp+="</table>";
				if(is==1){

					//alert(tmp);
					//$("#endhouse").attr("disabled","disabled");
					$("#prespan").show(); 
					$("#prespan").html('<button type="button" class="submit radius2" id="btn" onClick="savepacking()">生成发货计划</button>'); 
					$("#showskulist").html(tmp);
				}
				if(data.length<=0)
				{
					$("#prespan").hide(); 
					$("#showskulist").html('');
				}
				 
    		   
			}
	   },"json");
}

function savepacking()
{
	if($("#transportmode").val()=="")
	{
		$("#showerr").html('<font colore=red>请选择运输方式</font>!');
		return;
	}
	$("#theFrom").submit();
}


/********
**	d 对象
**  goodsno t_overseapurchasing ID号
**  cod 可放入箱子数
**  sendnums 实际需要发货数
**  container 可选择的箱号
*/
function altshone(d,goodsno,cod){
	if(cod==9999)
	{
		return;
	}
	$("#showerr"+goodsno).html('');
	var inputvalue = d.value;	//输入值
	if(cod){
		var oldnum =  document.getElementById(cod+"oldnum"+goodsno);	//可放入货柜数
	}else{
		var oldnum =  document.getElementById("oldnum"+goodsno);	//可放入货柜数

	}
	
	if(inputvalue==""){
		return;
	}
	if(parseInt(inputvalue) > parseInt(cod)){
		$("#showerr"+goodsno).html('装箱数量超过计划发货数量');
		//d.value = cod;
		return;
	}
	
}
function addRow(id) {

	var skuname = $("#skuname").val();
	var innerHTML="";
	 $.post("/oversea/ajaxbutton", {"op": "onegoods","skuname":skuname,"planid":id},
		 function(data){
		 if(data==201)
		 {
			alert("本次发货计划中未有找到该SKU!");
			return;
		 }else{
			 data = eval(data);
		 for(var i=0;i<data.length;i++){
			 innerHTML+= '<tr><td>'+data[i].sku+'<input type="hidden" name="TDid[]" value='+data[i].pid+'></td>';
			 innerHTML+= ' <td>'+data[i].createUser+'</td>';
			 innerHTML+= ' <td>'+data[i].skunum+'</td>';
			 innerHTML+= ' <td>'+data[i].sendnums+'</td>';
			 innerHTML+="<td><input type='hidden' name='TDcostprice[]'  value="+data[i].costprice+">";
			 innerHTML+= '<input type="text" name="TDnowbuynum[]" class="width100" onBlur="altshone(this,'+data[i].pid+',9999)" ></td></tr>';
		 }
		 $("#addrowlist").html(innerHTML);

	}
	
		},"json");

	
	
	
   }

function showaddRow()
{
	$("#showrow").show();
}
function changstatus(t,id,type){

	if(confirm("你确定执行此操作?"))
	{
		$.post("/oversea/ajaxbutton", {"op": "changstatus","t":t,"id":id,"type":type},
		 function(data){
				alert("操作成功！");
				if(type==1)
				{
					window.location.href = "/oversea/deliveryplanlist";
				}else{
					window.location.href = "/oversea/transportlist";
				}
				return;
	   },"json");
	  
	}
}
function savecompare()
{
	if($("#box").val()=="")
	{
		$("#boxerr").html('&nbsp;<font color=red>请填写箱号！</font>');
		return false;
	}
	
	if($("#weight").val()=="")
	{
		$("#weighterr").html('&nbsp;<font color=red>请填写重量！</font>');
		return false;
	}

	
	$("#theFrom").submit();
}
function getbox()
{
	$("#boxerr").html('');
	var boxid = $("#groupid").html()+$("#box").val();
	if(boxid)
	{
		$.post("/oversea/ajaxbutton", {"op": "boxid","boxid":boxid},
		 function(data){
				
			if(data==201)
			{
				$("#boxerr").html('&nbsp;<font color=red>箱号已经存在！</font>');
				$("#box").val('')
				return false;
			}
			

	   },"json");
	}
	
}
function deliveryplanlist(id)
{
	if(confirm("确定移除?"))
	{
		$.post("/oversea/ajaxbutton", {"op": "deldelitt","id":id},
		 function(data){
				
			document.location.href = "/oversea/deliveryplanlist";
				return;
			

	   },"json");
	}
}

var totalnum = 1;
function showinput()
{
	var inputn = document.getElementById("input1");
	var str=inputn.innerHTML;
	var num=1;
	for(var i=1;i<=num;i++){
		totalnum=totalnum+i;
		str += "<tr id=las"+totalnum+">";
        str+="<td><input type=\"text\" class=\"width100\"   name=\"freight[]\"  />&nbsp;&nbsp;运费说明：<input type=\"text\" class=\"width100\"   name=\"projectdateremake[]\"  /><a href=javascript:void(0) onclick=delfileinput("+totalnum+")><span style=\"padding:5px 0 0\" class=\"c9\">移除</span></a></td>";
        str+="</tr>";
	}
	$("#input1").html(str);
	
}
function delfileinput(id)
{
	if(confirm("确定移除？"))
	{
		$("#las"+id).remove();
	}
}
function allSelect(id) {

	var vote_arr = document.getElementsByName(id);

	for(var j = 0; j < vote_arr.length; j++)
	{
	   if(vote_arr[j].checked == false)
	   {
	      vote_arr[j].checked=true;
	   }else{
		  vote_arr[j].checked=false;
	   }
	   
	}
 }

function chggoodsstatus()
{
    var vote_arr = document.getElementsByName("ppid[]");
	var idarr = new Array();
	var i=0;
	var str="";
	for(var j = 0; j < vote_arr.length; j++)
	{
	   if(vote_arr[j].checked == true)
	   {
	       idarr[i] = vote_arr[j].value;
		   str += vote_arr[j].value+",";
		   i++;
	   }
	   
	}
	if(i<=0){
			alert("未选中数据");
		} else{
			//s=1问题订单
				 $.post("/oversea/ajaxbutton", {"op": "orderproblem","uid":str},
				 function(data){
					 if(data==201)
					 {
						alert("所选择的项始发地不一样");
						return;
					 }
					  if(data==202)
					 {
						alert("所选择的目的地不一样");
						return;
					 }
					  if(data==200)
					 {
						window.location='/oversea/transportboxtypedetail?uid='+str;
						return;
					 }
				   		//	
				   },"json");
			
		}
}
function do_qa(id)
{
	//AWS.ajax_post($('#qaform'));
	$("#id").val(id);
	$('#returndataModal').modal('show');
}
function ediplan(id)
{
	 $.post("/oversea/ajaxbutton", {"op": "getplanstatus","id":id},
				 function(data){
					if(data !=201)
					{
						$("#id").val(data.planid);
						$("#statusid").val(data.id);
						$("#projectdate").val(data.projectdate);
						$("#endprojectdate").val(data.endprojectdate);
						$("#freight").val(data.freight);
						$("#projectdateremake").val(data.projectdateremake);
						$("#ck").val(data.ck);
						$("#cargostatus").val(data.cargostatus);
						$("#carrier").val(data.carrier);
						$("#transportmode").val(data.transportmode);
						$('#returndataModal').modal('show');
					}
				   },"json");
	
}
function doqa()
{
	AWS.ajax_post($('#qaform'));
	$('#returndataModal').modal('hide');
}